package com.neusoft.elm.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.neusoft.elm.View.BusinessView;
import com.neusoft.elm.dao.BusinessDao;
import com.neusoft.elm.po.Business;
import com.neusoft.elm.util.DBUtil;

public class BusinessDaoImpl implements BusinessDao {
	Connection con=null;
	PreparedStatement pst =null;
	ResultSet rs = null;


	@Override
	public List<Business> listBusiness( String businessName,String businessAddress){
		
		//String sql = "SELECT * FROM business WHERE 1 = 1";
		StringBuffer sql = new StringBuffer("SELECT * FROM business WHERE 1 = 1  "); //加空格
		if(businessName != null&& !businessName.equals("")){
			sql.append(" AND businessName LIKE '%" + businessName + "%' ");
			
		}
		//商家地址
		if(businessAddress != null&& ! businessAddress.equals("")){
			sql.append("AND businessAddress LIKE '%"+businessAddress+"%' ");
			
		}
		List<Business> list = new ArrayList<>();
		// Business business = new Business();//TODO 错误???
		 //TODO .............
		//1.连接数据库
		try{
		 con = DBUtil.getConnection();
		 pst= con.prepareStatement(sql.toString());
	     rs= pst.executeQuery();
	     
	     while (rs.next()) {
	    	Business business = new Business();
	       business.setBusinessAddress(rs.getString("businessAddress"));
	       business.setBusinessExplain(rs.getString("businessExplain"));
	       business.setBusinessId(rs.getInt("businessId"));
	       business.setBusinessName(rs.getString("businessName"));
	       business.setDeliveryPrice(rs.getDouble("deliveryPrice"));
	       business.setPassword(rs.getString("password"));
	       business.setStarPrice(rs.getDouble("starprice"));
	       list.add(business);
	    	
	    	 
			
		}
		}catch(SQLException e){
			e.printStackTrace();
		}finally{
			
			DBUtil.close(rs, pst, con);
		}
		return list;
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}















	@Override
	public List<Business> listBusiness() {
		// TODO Auto-generated method stub
		return null;
	}

}
